﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DiscMaster.Web.Models;

namespace DiscMaster.Web.Extensions
{
    public static class Data
    {
        public static Dictionary<string, string> GenderList()
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("", "not specified");
            dict.Add("0", "male");
            dict.Add("1", "female");

            return dict;
        }
        public static List<DiscMaster.Web.Models.Match> GetByPlayer(this System.Data.Linq.Table<Match> matches, string playerid)
        {
            return matches.Where(m => m.MatchPlayers.Any(mp => mp.playerid.Equals(playerid))).ToList();
        }
        public static string ToPlacementString(this int number)
        {
            switch (number)
            {
                case 1:
                    return "first";
                case 2:
                    return "second";
                case 3:
                    return "third";
                case 4:
                    return "fourth";
                case 5:
                    return "fifth";
                case 6:
                    return "sixth";
                case 7:
                    return "seventh";
                case 8:
                    return "eigth";
                default:
                    return "?";
            }
        }
        public static List<T> Top<T>(this IEnumerable<T> list, int length)
        {
            List<T> ret = new List<T>();
            int innercount = 0;
            foreach (var item in list)
            {
                innercount++;
                ret.Add(item);
                if (innercount == length)
                {
                    return ret;
                }
            }
            return ret;
        }
    }
}
